<%@ page language="java" import="java.util.*,java.net.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'dologin.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <h1>登陆成功！！</h1>
  <hr>
  <br>
  <br>
  <br>
  <% request.setCharacterEncoding("utf-8");
  //判断用户是否勾选Cookie
  String[] isUserCookies=request.getParameterValues("isUserCookie");
  if(isUserCookies!=null&&isUserCookies.length>0){
  //获取用户输入的用户名和密码
      String username=URLEncoder.encode(request.getParameter("username"),"utf-8");
      String password=URLEncoder.encode(request.getParameter("password"),"utf-8");
      //把用户名和密码保存在cookie对象里面
      Cookie usernameCookie=new Cookie("username",username);
      Cookie passwordCookie=new Cookie("password",password);
      //设置保存信息的时间
      usernameCookie.setMaxAge(864000);
      passwordCookie.setMaxAge(864000);
      //保存到response中
      response.addCookie(usernameCookie);
      response.addCookie(passwordCookie);
  }else{
        Cookie[] cookies=request.getCookies();
        if(cookies!=null&&cookies.length>0){
        for(Cookie c:cookies){
               if(c.getName().equals("username")||c.getName().equals("password")){
               c.setMaxAge(0);
               response.addCookie(c);
               }
        }
        }
  
  }
  
   %>
  <a href="users.jsp" target="_blank">查看用户信息</a>
  </body>
</html>
